package openapi

import (
	"net/http"
	"strings"

	"github.com/getkin/kin-openapi/openapi3"
)

func GetOperation(pathItem *openapi3.PathItem, method string) *openapi3.Operation {
	method = strings.ToUpper(method)
	switch method {
	case http.MethodConnect:
		return pathItem.Connect
	case http.MethodDelete:
		return pathItem.Delete
	case http.MethodGet:
		return pathItem.Get
	case http.MethodHead:
		return pathItem.Head
	case http.MethodOptions:
		return pathItem.Options
	case http.MethodPatch:
		return pathItem.Patch
	case http.MethodPost:
		return pathItem.Post
	case http.MethodPut:
		return pathItem.Put
	case http.MethodTrace:
		return pathItem.Trace
	default:
		return nil
	}
}
